package org.hepeng.fabric.gateway.contract.spring;


import org.hepeng.fabric.contract.api.ContractProvider;
import org.hepeng.fabric.gateway.contract.proxy.ContractProxy;
import org.springframework.beans.factory.FactoryBean;

/**
 * @author he peng
 * @date 2022/3/26
 */


public class ContractFactoryBean<T> implements FactoryBean<T> {

    private Class<T> contractInterface;

    private ContractProvider contractProvider;

    public ContractFactoryBean() {}

    @Override
    public T getObject() throws Exception {
        return ContractProxy.newProxy(contractInterface , contractProvider);
    }

    @Override
    public Class<?> getObjectType() {
        return contractInterface;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }

    public Class<T> getContractInterface() {
        return contractInterface;
    }

    public void setContractInterface(Class<T> contractInterface) {
        this.contractInterface = contractInterface;
    }

    public ContractProvider getContractProvider() {
        return contractProvider;
    }

    public void setContractProvider(ContractProvider contractProvider) {
        this.contractProvider = contractProvider;
    }

    @Override
    public String toString() {
        return "ContractFactoryBean{" +
                "contractInterface=" + contractInterface +
                ", contractProvider=" + contractProvider +
                '}';
    }
}
